class code1 {
    //大根堆
    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> heap = new PriorityQueue<>((a,b)->(b-a));
        //放入
        for(int x:stones) {
            heap.offer(x);
        }

        //遍历堆
        while(heap.size()>1) {
            int x = heap.poll();
            int y = heap.poll();
            if(x>y) {
                heap.offer(x-y);
            }
        }
        return heap.size()==0?0:heap.peek();
    }
}
